import json
import os

redis_path = os.getenv('JIANMU_REDIS_PATH')
database = os.getenv('JIANMU_DATABASE')

datas = []
redis_import_file = '/tmp/redis_import.json'
with open(redis_path, 'r') as f:
    for line in f:
        data = json.loads(line)
        if database:
            data['db'] = int(database)
        datas.append(data)

with open(redis_import_file, 'w') as f:
    for data in datas:
        f.write(json.dumps(data) + '\n')
